﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NP.Demo.BLL
{
    public abstract class BLLBase<T> : IBLL<T> where T : class, new()
    {

        public string Add(T info)
        {
            throw new NotImplementedException();
        }

        public string Edit(T info)
        {
            throw new NotImplementedException();
        }

        public string Remove(T info)
        {
            throw new NotImplementedException();
        }

        public T GetById(Guid id)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Web窗体地址
        /// </summary>
        /// <param name="action">动作枚举值</param>
        /// <param name="parameters">页面参数</param>
        /// <returns>地址</returns>
        virtual public string WebFormUrl(Enum action, Dictionary<Enum, string> parameters = null)
        {
            SystemActions act = (SystemActions)Enum.Parse(typeof(SystemActions), action.ToString());
            string url = typeof(T).Name + action.ToString();
            url = url + "?Action=" + action.ToString();
            return this.GetWebPageUrlWithParameters(url, parameters);
        }

        /// <summary>
        /// 页面地址
        /// </summary>
        /// <param name="action">业务操作枚举</param>
        /// <returns></returns>
        virtual public string GetWebPageUrlWithParameters(string url, Dictionary<Enum, string> parameters)
        {
            url += url.Contains("?") ? "&" : "?";
            if (parameters != null)
            {
                foreach (KeyValuePair<Enum, string> kvp in parameters)
                {
                    url += kvp.Key.ToString() + "=" + kvp.Value + "&";
                }
            }
            return url.Substring(0, url.Length - 1);
        }

        /// <summary>
        /// 
        /// </summary>
        public enum SystemActions
        {
            Add,
            Edit,
            Detail,
            Remove
        }
    }
}
